package problem17;

import java.util.ArrayList;
import java.util.List;

//17.电话号码的字母组合
//https://leetcode.cn/problems/letter-combinations-of-a-phone-number/

class Solution {
    StringBuffer str = new StringBuffer();
    List<String> ret = new ArrayList<>();
    String[] map = {"","", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
    public List<String> letterCombinations(String digits) {
        if(digits.length() == 0) return ret;
        
        dfs(digits,0);
        return ret;
    }
    public void dfs(String digits, int pos) {
        if(pos == digits.length()) {
            ret.add(new String(str));
            return;
        }
        int k = digits.charAt(pos) - '0';
        for(int i = 0; i<map[k].length(); i++) {
            str.append(map[k].charAt(i));
            dfs(digits, pos+1);
            str.deleteCharAt(str.length()-1);
        }
    }
}